package com.cskaoyan.demo6.service;

import com.cskaoyan.demo6.bean.model.MarketBrand;
import com.cskaoyan.demo6.bean.model.MarketBrandExample;
import com.cskaoyan.demo6.bean.vo.HomeIndexVo;
import com.cskaoyan.demo6.mapper.MarketBrandMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description：
 * @Author：BLUEBLANK
 * @Date：2024/4/20 22:29
 */

@Service("brandService")
public class BrandServiceImpl implements BrandService {

    @Autowired
    MarketBrandMapper marketBrandMapper;


    @Override
    public List<HomeIndexVo.BrandListDTO> select(Integer offset, Integer brandLimit) {
        MarketBrandExample brandExample = new MarketBrandExample();
        brandExample.createCriteria().andDeletedEqualTo(false);
        PageHelper.offsetPage(offset, brandLimit);
        List<MarketBrand> marketBrands = marketBrandMapper.selectByExample(brandExample);

        List<HomeIndexVo.BrandListDTO> brand = new ArrayList<>();
        marketBrands.forEach(marketBrand -> {
            HomeIndexVo.BrandListDTO brandDTO = new HomeIndexVo.BrandListDTO();
            BeanUtils.copyProperties(marketBrand, brandDTO);
            brand.add(brandDTO);
        });
        return brand;
    }
}
